please need help in scheduling a  script

Hello Every one,

I have a requirement to create  a .txt file every hour. I create a .bat file with the following script "PS C:\> sharedservicesstarted.txt -path C:\ -name sharedservicesstarted.txt  -value (get-date).tostring() -Itemtype file"

I'm on windows server 2008r2. When i double click on the .bat file, a new "sharedservicesstarted.txt" files get created on the C:\,

but when i schedule the exact same file, its not creating the file and the last run result is shown as (0x1). Please need help.

Thanks

July 9th, 2015 3:32pm

What is this line supposed to do?

"PS C:\> sharedservicesstarted.txt -path C:\ -name sharedservicesstarted.txt  -value (get-date).tostring() -Itemtype file"

It is not any kind of script command or batch command.

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 3:51pm

Thanks Jrv.Its a power shell command, that just creates a text file "sharedservicesstarted.txt) to the desired location.

If this is not the right approach, can you please point me in the right direction? I want to create a .txt when a script is run and schedule the script to create the file at regular intervals.

Thanks


  • Edited by AmyBI 10 hours 42 minutes ago s
July 9th, 2015 4:02pm

This will create a new file:

New-Item -Path C:\ -Name sharedservicesstarted.txt -Value (Get-Date).ToString() -ItemType File

You have to save your script with .ps1 extension, not .bat.

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 5:42pm

Thanks Jrv.Its a power shell command, that just creates a text file "sharedservicesstarted.txt) to the desired location.

If this is not the right approach, can you please point me in the right direction? I want to create a .txt when a script is run and schedule the script to create the file at regular intervals.

Thanks


  • Edited by AmyBI Thursday, July 09, 2015 8:26 PM s
July 9th, 2015 7:57pm

This will create a new file:

New-Item -Path C:\ -Name sharedservicesstarted.txt -Value (Get-Date).ToString() -ItemType File

You have to save your script with .ps1 extension, not .bat.

Thanks Leif-Arne Helland. So i open a note pad paste this script and save as .ps1 extension, then schedule it using the task scheduler right? How do i test it manually , before scheduling it?

When i used the command prompt to run this command, i got an error message "New-Item is not a recognized internal or external command operable program or batch file'. Please suggest.


Free Windows Admin Tool Kit Click here and download it now
July 10th, 2015 9:19am

Thanks Leif-Arne Helland. So i open a note pad paste this script and save as .ps1 extension, then schedule it using the task scheduler right? How do i test it manually , before scheduling it?

When i used the command prompt to run this command, i got an error message "New-Item is not a recognized internal or external command operable program or batch file'. Please suggest.

Save Leif-Arne's script somewhere with a .ps1 extension. Then use the following options for the task:

Action: Start a program

Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add arguments: -ExecutionPolicy ByPass -File C:\Path\To\Script.ps1

July 10th, 2015 10:09am

You can test it manually in Windows PowerShell or Windows PowerShell ISE. It will not work in Command Prompt.

Please refer to Mike's post on how to schedule the script in Task Scheduler.

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2015 3:41pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics